<?php
class App_Module_Admin_Component_Blogs_Tpl_BlogList extends App_Module_Admin_Tpl_List
{
	protected $_showCells = array('title', 'author', 'icons');
	protected $_emptyListMessage = 'NO_BLOGS';
	
    public function GetList($page)
    {
        $onPage = Mozg_Cfg::Get('admin/blogs')->GetPerPage();
               
        $paginator = new Mozg_Paginator($page, $onPage);
       	$pattern = Mozg::Router('http')->Create('module=admin&ctrl=blogs&action=bloglist&bpage=__page__');
            	
        $icons = array(
        	array(
        	'add' => array(
        					'title' => 'ADD',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=blogs&action=addblog')
        					),
        	)
        );
        
        $objects = Mozg_Mapper::Get('Blogs')->GetList(array(), $paginator);
        $paginator->SetTotalCount(Mozg_Mapper::Get('Blogs')->GetTotalRows());
        $content = $this->CreateList($objects, $paginator, $pattern);
        
        return $this->GetTpl('Base')->LoadTemplate(Mozg_Lang::_('BLOGS'), $content, $icons);
    }
    
    protected function GetHeaderTitle()
    {
    	return Mozg_Lang::_('TITLE');
    }
    
    protected function GetHeaderAuthor()
    {
    	return Mozg_Lang::_('AUTHOR');
    }
    
	protected function GetCellTitle($obj)
	{
		$this->obj = $obj;
		return $this->render('blogs/list/_title.phtml');
	}
	
	protected function GetCellAuthor($obj)
	{
		return $obj->GetUser()->GetUserName();
	}
	
	protected function GetCellIcons($obj)
	{
        $icons = array(
        	'edit' => array(
        					'title' => 'EDIT',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=blogs&action=addblog&blog=' .$obj->GetId())
        					),

        	'delete' => array(
        					'title' => 'DELETE_BLOG_WITH_ARTICLES?',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=blogs&action=delblog&blog=' .$obj->GetId())
        					),

        );
		return $this->GetTpl('Icon')->GetIconSet($icons, 'list');
	}
}